package com.nf.test.dao.impl;/*
 *@Author: gjh
 *Date: 2025/2/2419:16
 *Describe:
 */

import com.nf.test.dao.StaffsDao;
import com.nf.test.model.pojo.Staffs;
import com.nf.test.utils.DBUtil;

import java.sql.ResultSet;

public class StaffsDaoImpl implements StaffsDao {

    @Override
    public ResultSet selStaffs() {
        String sql = "select * from staffs";
        ResultSet rst = DBUtil.executeQuery(sql,new Object[]{});
        return rst;
    }

    @Override
    public int addStaffs(Staffs staffs) {
        String sql = "insert into staffs(name,age,phone,sta_pos) values (?,?,?,?)";
        int count = DBUtil.executeUpdate(sql,new Object[]{staffs.getName(),staffs.getAge(),staffs.getPhone(),staffs.getStapos()});
        return count;
    }

    @Override
    public int delStaffs(int id) {
        String sql = "delete from staffs where id = ?";
        int count = DBUtil.executeUpdate(sql,new Object[]{id});
        return count;
    }

    @Override
    public int updStaffs(Staffs staffs) {
        String sql = "update staffs set name = ?,age = ?,phone = ?,sta_pos = ? where id = ?";
        int count  = DBUtil.executeUpdate(sql,new Object[]{staffs.getName(),staffs.getAge(),staffs.getPhone(),staffs.getStapos(),staffs.getId()});
        return count;
    }
}
